package cn.chenxiejia;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: Image7
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/1/24 16:02
 */
public class Imges7 {
    public static void main(String[] args) {
        try {
            var bi = ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("img/1.jpg"));
            int h = bi.getHeight();
            int w = bi.getWidth();

            int a = (int) (1.0 * h / w * 500);
            System.out.println(a);


            var i = new BufferedImage(500, a, 1);
            var m = i.createGraphics();

            m.drawImage(bi, 0, 0, 500, a, null);
            ImageIO.write(i, "jpg", new File("2.jpg"));
            m.dispose();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
